<?php
declare(strict_types=1);

namespace app\model;

use think\Model;

class MemberPackage extends Model
{
    protected $autoWriteTimestamp = true;

    // 状态常量
    const STATUS_NORMAL = 1; // 正常
    const STATUS_DISABLED = 2; // 禁用

    // 关联商家
    public function merchant()
    {
        return $this->belongsTo(Merchant::class);
    }

    // 关联用户套餐
    public function userPackages()
    {
        return $this->hasMany(UserPackage::class, 'package_id');
    }

    // 获取状态文字
    public function getStatusTextAttr()
    {
        $status = [
            self::STATUS_NORMAL => '正常',
            self::STATUS_DISABLED => '禁用'
        ];
        return $status[$this->status] ?? '未知';
    }

    // 是否可用
    public function isAvailable(): bool
    {
        return $this->status === self::STATUS_NORMAL;
    }
} 